<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JSDoc: Source: fruitMachine/fruitMachine.js</title>

    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

    <h1 class="page-title">Source: fruitMachine/fruitMachine.js</h1>

    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>/**
 * Class FruitMachine
 * @class
 * @classdesc 水果机游戏逻辑部分
 * @author pfan
 * 
 * @example
 *  new FruitMachine(this,{
 *    len: 9, //宫格个数
 *    ret: 9, //抽奖结果对应值1～9   
 *    speed: 100  // 速度值
 *    ],
 *    callback: (idx, award) => {
 *      //结束回调， 参数对应宫格索引，对应奖项    
 *    }
 *  })
 */
 class FruitMachine {

  /**
   * @constructs FruitMachine构造函数
   * @param  {Object} pageContext page路由指针
   * @param  {Object} opts      组件所需参数
   * @param  {Number} opts.len  宫格个数
   * @param  {Number} opts.ret  抽奖结果对应值1～9
   * @param  {Number} opts.speed  速度值
   * @param  {Function} opts.callback  结束回调
   */  
  constructor (pageContext, opts) {
    this.page = pageContext
    this.len = opts.len || 8
    this.ret = opts.ret
    this.speed = opts.speed
    this.isStart = false
    this.endCallBack = opts.callback
    this.page.start = this.start.bind(this)
  }

  start () {

    let { idx, ret, len, speed, isStart } = this
    if(isStart)return
    this.isStart = true
    let range = Math.floor(Math.random()*2 + 2)
    let count = 0
    let spd2 = speed*2
    !(function interval(self){
      setTimeout( () => {
        count++
        if(count > range * len){
          speed = spd2
        }
        if(count != (range + 1) * len + ret ){
          interval(self)
        }else{
          self.isStart = false
          self.endCallBack &amp;&amp; self.endCallBack()
        }

        self.page.setData({
          machine: {
            idx: count % 8  == 0 ? 8 : count % 8
          }
        })
        
      }, speed)
    })(this)
  }

  reset () {
     this.page.setData({
      machine: {
        idx: ''
      }
    })   
  }

}

export default FruitMachine</code></pre>
        </article>
    </section>




</div>

<nav>
    <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Card.html">Card</a></li><li><a href="FruitMachine.html">FruitMachine</a></li><li><a href="Lock.html">Lock</a></li><li><a href="Machine.html">Machine</a></li><li><a href="Scratch.html">Scratch</a></li><li><a href="Shake.html">Shake</a></li><li><a href="Wheel.html">Wheel</a></li></ul><h3>Global</h3><ul><li><a href="global.html#getDis">getDis</a></li><li><a href="global.html#runAsync">runAsync</a></li></ul>
</nav>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Sep 19 2017 21:36:13 GMT+0800 (HKT)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
